﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Security.Permissions;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;


namespace MYWebsite
{
[
    AspNetHostingPermission(SecurityAction.Demand,
        Level = AspNetHostingPermissionLevel.Minimal),
    AspNetHostingPermission(SecurityAction.InheritanceDemand,
        Level = AspNetHostingPermissionLevel.Minimal),

    DefaultProperty("Text"), ToolboxData(@"<{0}:GalleryControl runat=""server""> </{0}:GalleryControl>")]
    [SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]

    public class GalleryControl : Button
    {
        private string imgURL;

    #region Constructor
        public GalleryControl() { }
    #endregion

    #region Properties
    [Bindable(true)]
    [Category("Appearance")]
    [Description("ShowImage")]
    [DefaultValue(false)]
    public bool ShowImage { get; set; }


    [DefaultValue("")]
    [Browsable(true)]

    [UrlProperty]
    public string ImageUrl {get;set;}
    public string Id{get;set;}
    public string CSSClass{get;set;}
    public bool Enabled{get;set;}
    public string ImageId{get;set;}

    #endregion

    #region Override
    protected override void Render(HtmlTextWriter writer)
    {
        writer.AddAttribute(HtmlTextWriterAttribute.Id, String.Format("tbl{0}", this.Id));
        writer.AddAttribute(HtmlTextWriterAttribute.Cellpadding, "0");
        writer.AddAttribute(HtmlTextWriterAttribute.Cellspacing, "0");
        writer.AddAttribute(HtmlTextWriterAttribute.Border, "0");
        writer.AddAttribute(HtmlTextWriterAttribute.Class, "imgBtnWrapperStd");
        if (!this.Enabled)
            writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "disabled");
        writer.RenderBeginTag(HtmlTextWriterTag.Ul);


        writer.AddAttribute(HtmlTextWriterAttribute.Class, "btnContainer");
        writer.RenderBeginTag(HtmlTextWriterTag.Div);
        if (this.ShowImage)
        {

            writer.AddAttribute(HtmlTextWriterAttribute.Src, ResolveClientUrl(this.ImageUrl));
            writer.AddAttribute(HtmlTextWriterAttribute.Align, "absMiddle");
            writer.RenderBeginTag(HtmlTextWriterTag.Img);
            writer.RenderEndTag();
        }
        writer.AddAttribute(HtmlTextWriterAttribute.Class, this.CssClass);
        writer.AddAttribute(HtmlTextWriterAttribute.For, this.ImageId);
        base.Render(writer);
        writer.RenderEndTag();
        writer.RenderEndTag();

    }
    protected override void OnPreRender(EventArgs e)
    {
        base.OnPreRender(e);

    }
    #endregion
    }
}